package cn.stu.flowable.service.impl;


import cn.stu.common.utils.R;
import cn.stu.common.utils.UserHolder;
import cn.stu.flowable.domain.req.PageReq;
import cn.stu.flowable.service.ISysFormService;
import cn.stu.framework.entity.SysForm;
import cn.stu.framework.mapper.SysFormMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 流程表单Service业务层处理
 *
 * @author Tony
 * @date 2021-04-03
 */
@Service
@AllArgsConstructor
public class SysFormServiceImpl implements ISysFormService {
    private SysFormMapper sysFormMapper;

    /**
     * 查询流程表单
     *
     * @param formId 流程表单ID
     * @return 流程表单
     */
    @Override
    public SysForm selectSysFormById(Long formId) {
        return sysFormMapper.selectSysFormById(formId);
    }

    /**
     * 查询流程表单列表
     *
     * @param sysForm 流程表单
     * @param pageReq 寻呼请求
     * @return 流程表单
     */
    @Override
    public R<Page<SysForm>> selectSysFormList(PageReq pageReq, SysForm sysForm) {
        Page<SysForm> page = new Page<>(pageReq.getPageNum(), pageReq.getPageSize());
        sysFormMapper.selectSysFormList(page, sysForm);
        return R.ok(page);
    }

    /**
     * 新增流程表单
     *
     * @param sysForm 流程表单
     * @return 结果
     */
    @Override
    public int insertSysForm(SysForm sysForm) {
        sysForm.setCreateTime(LocalDateTime.now());
        Long userId = UserHolder.getUser().getUserId();
        sysForm.setCreateId(userId);
        sysForm.setUpdateId(userId);
        return sysFormMapper.insertSysForm(sysForm);
    }

    /**
     * 修改流程表单
     *
     * @param sysForm 流程表单
     * @return 结果
     */
    @Override
    public int updateSysForm(SysForm sysForm) {
        sysForm.setUpdateTime(LocalDateTime.now());
        sysForm.setUpdateId(UserHolder.getUser().getUserId());
        return sysFormMapper.updateSysForm(sysForm);
    }

    /**
     * 批量删除流程表单
     *
     * @param formIds 需要删除的流程表单ID
     * @return 结果
     */
    @Override
    public int deleteSysFormByIds(Long[] formIds) {
        return sysFormMapper.deleteSysFormByIds(formIds);
    }

    /**
     * 删除流程表单信息
     *
     * @param formId 流程表单ID
     * @return 结果
     */
    @Override
    public int deleteSysFormById(Long formId) {
        return sysFormMapper.deleteSysFormById(formId);
    }
}
